package ihm.listener;

import ihm.view.View;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ListenerHandler {
	
	private static Map<Class<?>, List<View>> listeners;
	
	static {
		listeners = new HashMap<Class<?>, List<View>>();
	}
	
	public static void addView(Class<?> clazz, View view) {
		List<View> views = listeners.get(clazz);
		if (views == null) {
			views = new ArrayList<View>();
		}
		views.add(view);
	}
	
	public static List<View> getViews(Class<?> clazz) {
		List<View> views = listeners.get(clazz);
		if (views == null) {
			views = new ArrayList<View>();
		}
		return views;
	}
	
	public static void update(Class<?> clazz) {
		for (View view : getViews(clazz)) {
			view.update();
		}
	}
}
